import { ref, computed } from 'vue'
import { defineStore } from 'pinia'


export const useCounterStore = defineStore('counter', () => {
  //定义数据(state)
  const count = ref(0)
  //getter定义
  const doubleCount = computed(() => count.value * 2)
  //定义数据修改方法(action 同步+异步)
  function increment() {
    count.value++
  }
  const token = ref('')
  const name=ref('')
  const phone=ref('')
  //定义存入用户信息的方法
  function setUserInfo(userInfo:{token:string,name:string,phone:string}){
    token.value=userInfo.token
    name.value=userInfo.name
    phone.value=userInfo.phone
  }
  //定义清除用户信息的方法
  function clearUserInfo(){
    token.value=''
    name.value=''
    phone.value=''
  }
   //以对象的方式return供组件使用   
  return { count, doubleCount,increment,token,name,phone,setUserInfo,clearUserInfo}
},{
  persist:true
})
